package newcoder_exp.justPractise;

import tree.*;
import org.junit.*;

public class NC9 {
    public class Solution {
        public boolean hasPathSum (TreeNode root, int sum) {
            return preOrder(root, 0, sum);
        }
        
        public boolean preOrder(TreeNode root, int cur, int sum) {
            if (root == null) {
                return cur == sum;
            }
            if (cur >= sum) {
                return false;            
            }
            cur += root.val;
            return preOrder(root.left, cur, sum) || preOrder(root.right, cur, sum);
        }
    }

    @Test
    public void test() {
        Solution s = new Solution();
        TreeNode root = null;
        boolean res = s.hasPathSum(root, 0);
        System.out.println(res);
    }
}
